#include "basethread.h"

using namespace ThreadLib;

template<>
ThreadManage*   Singleton<ThreadManage>::g_pInstance = NULL;

AbstractThread::AbstractThread()
{
    m_threadID = 0;
}

AbstractThread::~AbstractThread()
{
    ThreadLib::Kill(m_threadID);
    m_threadID = 0;
}

ThreadManage::ThreadManage()
{
}

void    ThreadManage::registerThread(int   atype, AbstractThread* pThread)
{
    g_threadRegisterMutex.lock();
    if(atype < THREAD_TYPE_MAX)
    {
        g_threadArray[atype] = pThread;
    }
    g_threadRegisterMutex.unLock();
}

AbstractThread*    ThreadManage::getThreadOfType(int   aType)
{
    g_threadRegisterMutex.lock();
    AbstractThread* ret = NULL;
    if(aType < THREAD_TYPE_MAX)
    {
        ret = g_threadArray[aType];
    }
    g_threadRegisterMutex.unLock();
    return ret;
}
